define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'extension/orders/index' + location.search,
                    add_url: 'extension/orders/add',
                    // edit_url: 'extension/orders/edit',
                    // del_url: 'extension/orders/del',
                    multi_url: 'extension/orders/multi',
                    import_url: 'extension/orders/import',
                    table: 'orders',
                }
            });

            var table = $("#table");
            // Fast.config.openArea = ['80%','70%'];
            // //在普通搜索渲染后
            // table.on('post-common-search.bs.table', function (event, table) {
            //     var form = $("form", table.$commonsearch);
            //     $("input[name='invite']", form).addClass("selectpage").data("source", "general/staff/index").data("primaryKey", "invite").data("field", "invite").data("orderBy", "id desc");
            //     Form.events.cxselect(form);
            //     Form.events.selectpage(form);
            // });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns:true,
                fixedRightNumber:1,
                fixedNumberWidth:200,
                search: false,
                columns: [
                    [
                        {field: 'order_sn', title: __('订单编号'), operate: 'LIKE',
                            formatter:function(value,row,index){
                                var html = value;
                                if(row.is_safe === 1){
                                    html += '【包赔】';
                                }
                                return html;
                            }
                        },
                        {field: 'amount', title: __('订单金额'), operate:'BETWEEN'},
                        {field: 'game', title: __('游戏名称/区服'), operate: 'LIKE',
                            formatter:function(value,row,index){
                                var html = value+'/';
                                if(row.plat != null){
                                    html += row.plat+'/';
                                }
                                if(row.operator != null){
                                    html += row.operator+'/';
                                }
                                if(row.area != null){
                                    html += row.area+'/';
                                }
                                if(row.server != null){
                                    html += row.server;
                                }
                                return html;
                            }
                        },
                        {field: 'goods_sn', title: __('商品ID'), operate: 'LIKE'},
                        {field: 'ontime', title: __('订单时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,cellStyle: {css: {"max-width": "100px","white-space":"pre-line","word-wrap":"break-word","word-break":"break-all"}}},
                        {field: 'status', title: __('状态'),searchList: {"1":"待支付","2":"待发货","3":"已发货","4":"挂单","5":"已完成","7":"已撤单","8":"待审核","9":"取消订单","11":"待验证","12":"待确认"}, formatter: Table.api.formatter.flag},
                        {field: 'nickname', title: __('操作员工'), operate: 'LIKE'},
                        {field: 'admin_invite', title: __('员工工号'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'info',
                                    text: __(''),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'extension/orders/info',

                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});


